package com.bmps.springcloud.insuredmicroservice.service.underwrite;

import com.bmps.springcloud.common.response.TaskResponseModel;
import com.bmps.springcloud.common.utils.CalculationUtils;
import com.bmps.springcloud.common.utils.IDCardCheck;
import com.bmps.springcloud.insuredmicroservice.config.accept.ProductConfig;
import com.bmps.springcloud.insuredmicroservice.config.accept.SwitchConfig;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AgencyConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.RiskConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.UnderWriteConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.PersonModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.*;
import com.bmps.springcloud.insuredmicroservice.model.trail.TrialPersonModel;
import com.bmps.springcloud.insuredmicroservice.model.underwrite.InsuredModel;
import com.bmps.springcloud.insuredmicroservice.repository.accept.coresystem.AccountInfoRepository;
import com.bmps.springcloud.insuredmicroservice.repository.accept.coresystem.UserInfoRepository;
import com.bmps.springcloud.insuredmicroservice.repository.underwrite.coresystem.InsuredCoreRepository;
import com.bmps.springcloud.insuredmicroservice.service.RedisService;
import com.bmps.springcloud.insuredmicroservice.service.amnt.strategy.AmntStrategy;
import com.bmps.springcloud.insuredmicroservice.service.amnt.strategy.AmntStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.calculate.DeathLiabilityInsuranceService;
import com.bmps.springcloud.insuredmicroservice.service.trial.strategy.TrialStrategy;
import com.bmps.springcloud.insuredmicroservice.service.trial.strategy.TrialStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.accident.AccidentStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.accident.AccidentStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.accumulated.AccumulatedStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.accumulated.AccumulatedStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.addprem.AddPremStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.addprem.AddPremStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.hospital.HospitalStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.hospital.HospitalStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.insurance.InsuranceStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.insurance.InsuranceStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.minordeath.MinorDeathStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.minordeath.MinorDeathStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.traffic.TrafficStrategy;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.traffic.TrafficStrategyFactory;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lyw
 * @date 2019-07-30 10:02:32
 */
@Service
public class AcceptServiceImpl implements AcceptService {

    private static Logger logger = LoggerFactory.getLogger(AcceptServiceImpl.class);

    private final RedisService redisService;

    private final ProductConfig productConfig;

    private final InsuredCoreRepository insuredCoreRepository;

    private final AccountInfoRepository accountInfoRepository;

    private final UserInfoRepository userInfoRepository;

    private final DeathLiabilityInsuranceService deathLiabilityInsuranceService;

    private final SwitchConfig switchConfig;

    public AcceptServiceImpl(RedisService redisService, ProductConfig productConfig,
                             InsuredCoreRepository insuredCoreRepository, AccountInfoRepository accountInfoRepository, UserInfoRepository userInfoRepository, DeathLiabilityInsuranceService deathLiabilityInsuranceService, SwitchConfig switchConfig) {
        this.redisService = redisService;
        this.productConfig = productConfig;
        this.insuredCoreRepository = insuredCoreRepository;
        this.accountInfoRepository = accountInfoRepository;
        this.userInfoRepository = userInfoRepository;
        this.deathLiabilityInsuranceService = deathLiabilityInsuranceService;
        this.switchConfig = switchConfig;
    }

    @Override
    public TaskResponseModel checkInsuredRoles(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        taskResponseModel.setKey(key);
        try {
            InsuranceStrategy insuranceStrategy = InsuranceStrategyFactory.getInsuranceStrategy(productModel.getProdCode());
            if (insuranceStrategy != null) {
                InsuredModel insuredModel = insuranceStrategy.checkInsuredRolesByRiskCode(acceptRequestDataModel, insuredCoreRepository, productModel, productConfig);
                if (!StringUtils.equals(insuredModel.getResultCode(), AcceptConstant.RESULT_SUCCESS_CODE)) {
                    taskResponseModel.setResultCode(insuredModel.getResultCode());
                    taskResponseModel.setResultMessage(insuredModel.getResultMessage());
                }
            }
            logger.info("【投核保校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage("投核保校验:" + AcceptConstant.RESULT_FAIL_MESSAGE);
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkAccumulatedRiskInsurance(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            AccumulatedStrategy accumulatedStrategy = Objects.requireNonNull(AccumulatedStrategyFactory.getInsuranceStrategy(productModel.getProdCode()));
            InsuredModel insuredModel = accumulatedStrategy.checkAccumulatedRolesByRiskCode(acceptRequestDataModel, insuredCoreRepository, productModel, redisService, productConfig);
            if (!StringUtils.equals(insuredModel.getResultCode(), AcceptConstant.RESULT_SUCCESS_CODE)) {
                taskResponseModel.setResultCode(insuredModel.getResultCode());
                taskResponseModel.setResultMessage(insuredModel.getResultMessage());
            }
            logger.info("【累计风险保额校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage("累计风险保额校验:" + AcceptConstant.RESULT_FAIL_MESSAGE);
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkPremiumTrialCalculation(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            //TrialStrategy trialStrategy = Objects.requireNonNull(TrialStrategyFactory.getTrialStrategy(productModel.getProdCode()));
            TrialStrategy trialStrategy = TrialStrategyFactory.getTrialStrategy(productModel.getProdCode());
            if (trialStrategy == null) {
                taskResponseModel.setBigDecimal(productModel.getPrem());
            } else {
                TrialPersonModel trialPersonModel = trialStrategy.premiumTrialCalculationPrepare(productModel, acceptRequestDataModel.getRequest(), redisService);
                logger.info("【TrialPersonModel对象】" + trialPersonModel.toString());
                taskResponseModel.setBigDecimal(CalculationUtils.getCalculateResult(trialPersonModel.getFormula(), trialPersonModel.getMap()));
                logger.info("【保费试算校验結果】" + taskResponseModel.toString());
            }
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】", e);
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage(String.format(AcceptConstant.TRIAL_RESULT_FAIL_MESSAGE, productModel.getProdCode(), productModel.getProdName()));
            return taskResponseModel;
        }

    }

    @Override
    public TaskResponseModel checkHospitalRiskInsurance(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            HospitalStrategy hospitalStrategy = Objects.requireNonNull(HospitalStrategyFactory.getInsuranceStrategy(productModel.getProdCode()));
            InsuredModel insuredModel = hospitalStrategy.checkHospitalRolesByRiskCode(acceptRequestDataModel, insuredCoreRepository, productModel, redisService, productConfig);
            if (!StringUtils.equals(insuredModel.getResultCode(), AcceptConstant.RESULT_SUCCESS_CODE)) {
                taskResponseModel.setResultCode(insuredModel.getResultCode());
                taskResponseModel.setResultMessage(insuredModel.getResultMessage());
            }
            logger.info("【住院险累计风险保额校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage("住院险累计风险保额校验:" + AcceptConstant.RESULT_FAIL_MESSAGE);
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkTrafficRiskInsurance(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            TrafficStrategy trafficStrategy = Objects.requireNonNull(TrafficStrategyFactory.getInsuranceStrategy(productModel.getProdCode()));
            InsuredModel insuredModel = trafficStrategy.checkTrafficRolesByRiskCode(acceptRequestDataModel, insuredCoreRepository, productModel, redisService, productConfig);
            if (!StringUtils.equals(insuredModel.getResultCode(), AcceptConstant.RESULT_SUCCESS_CODE)) {
                taskResponseModel.setResultCode(insuredModel.getResultCode());
                taskResponseModel.setResultMessage(insuredModel.getResultMessage());
            }
            logger.info("【交通意外险累计风险保额校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage("交通意外险累计风险保额校验:" + AcceptConstant.RESULT_FAIL_MESSAGE);
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkMinorDeathLiability(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            MinorDeathStrategy strategy = Objects.requireNonNull(MinorDeathStrategyFactory.getInsuranceStrategy(productModel.getProdCode()));
            InsuredModel insuredModel = strategy.checkDeathLiabilityByRiskCode(acceptRequestDataModel, productModel, redisService, deathLiabilityInsuranceService);
            if (!StringUtils.equals(insuredModel.getResultCode(), AcceptConstant.RESULT_SUCCESS_CODE)) {
                taskResponseModel.setResultCode(insuredModel.getResultCode());
                taskResponseModel.setResultMessage(insuredModel.getResultMessage());
            }
            logger.info("【未成年人死亡责任风险保额校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage("未成年人死亡责任风险保额校验:" + AcceptConstant.RESULT_FAIL_MESSAGE);
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkAccidentInsuranceAmount(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel, Object object) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            AccidentStrategy strategy = Objects.requireNonNull(AccidentStrategyFactory.getStrategy(productModel.getProdCode()));
            InsuredModel insuredModel = strategy.checkAccidentInsuranceAmount(acceptRequestDataModel, insuredCoreRepository, productModel, redisService, productConfig, object);
            if (!StringUtils.equals(insuredModel.getResultCode(), AcceptConstant.RESULT_SUCCESS_CODE)) {
                taskResponseModel.setResultCode(insuredModel.getResultCode());
                taskResponseModel.setResultMessage(insuredModel.getResultMessage());
                taskResponseModel.setBigDecimal(insuredModel.getSum());
            }
            logger.info("【意外险风险保额校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage("意外险风险保额校验:" + AcceptConstant.RESULT_FAIL_MESSAGE);
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkAmntTrialCalculation(String key, ProductModel productModel, AcceptRequestDataModel acceptRequestDataModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        String riskCode = productModel.getProdCode();
        try {
            // 20201223增加 至尊寿险和安新喜的保费校验 即使一个险种配置多条数据也能处理
            if (StringUtils.equals(riskCode, RiskConstant.LWT006) ||
                    StringUtils.equals(riskCode, RiskConstant.NPT011)) {
                List<Map<String, String>> mapList = insuredCoreRepository.getStartingPremium(riskCode);
                if (CollectionUtils.isNotEmpty(mapList)) {
                    for (Map<String, String> x : mapList) {
                        double min = Double.parseDouble(x.get("min"));
                        double base = Double.parseDouble(x.get("base"));
                        if (productModel.getPrem().compareTo(BigDecimal.valueOf(min)) < 0) {
                            return taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE).
                                    setResultMessage(String.format(UnderWriteConstant.STARTING_PREMIUM_MESSAGE, riskCode, productModel.getPrem(), min));
                        }
                        if (productModel.getPrem().doubleValue() % base != 0) {
                            return taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE).
                                    setResultMessage(String.format(UnderWriteConstant.BASE_PREMIUM_MESSAGE, riskCode, base));
                        }
                    }
                }
            }
            AmntStrategy amntStrategy = Objects.requireNonNull(AmntStrategyFactory.getAmntStrategy(productModel.getProdCode()));
            TrialPersonModel trialPersonModel = amntStrategy.amntTrialCalculation(productModel, acceptRequestDataModel.getRequest(), redisService);
            logger.info("【计算保额结果】" + trialPersonModel.toString());
            BigDecimal amntResult = CalculationUtils.getCalculateResult(trialPersonModel.getFormula(), trialPersonModel.getMap());
            amntResult = amntResult.setScale(2, BigDecimal.ROUND_HALF_UP);
            taskResponseModel.setAmntResult(amntResult);
            if (amntResult.compareTo(productModel.getAmnt()) != 0) {
                taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
                taskResponseModel.setResultMessage(String.format(AcceptConstant.AMNT_PREMIUM_MESSAGE, productModel.getProdCode(), productModel.getProdName()
                        , productModel.getAmnt(), amntResult));
            }
            logger.info("【计算保额校验結果】" + taskResponseModel.toString());
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【" + acceptRequestDataModel.getRequest().getPolicyInfo().getContNo() + "】" + e.getMessage());
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage(String.format(AcceptConstant.AMNT_RESULT_FAIL_MESSAGW, productModel.getProdCode(), productModel.getProdName()));
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel calculationAddPrem(String key, ProductModel productModel, RequestModel requestModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel();
        taskResponseModel.setKey(key);
        taskResponseModel.setResultCode(AcceptConstant.RESULT_SUCCESS_CODE);
        taskResponseModel.setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        try {
            AddPremStrategy strategy = Objects.requireNonNull(AddPremStrategyFactory.getStrategy(productModel.getProdCode()));
            TrialPersonModel trialPersonModel = strategy.calculateAddPrem(productModel, requestModel, redisService);
            logger.info("【增加保费计算要素】" + trialPersonModel.toString());
            BigDecimal addPrem = CalculationUtils.getCalculateResult(trialPersonModel.getFormula(),
                    trialPersonModel.getMap()).setScale(2, BigDecimal.ROUND_HALF_UP);
            taskResponseModel.setBigDecimal(addPrem);
            if (addPrem.compareTo(productModel.getAddPrem()) != 0) {
                taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
                taskResponseModel.setResultMessage(String.format(AcceptConstant.ADD_PREM_ERROR, productModel.getProdCode(), productModel.getAddPrem(), addPrem));
            }
            return taskResponseModel;
        } catch (Exception e) {
            logger.error("【增加保费计算异常】 riskcode=" + productModel.getProdCode(), e);
            taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE);
            taskResponseModel.setResultMessage(String.format(AcceptConstant.ADD_PREM_RESULT_FAIL_MESSAGE, productModel.getProdCode(), productModel.getProdName()));
            return taskResponseModel;
        }
    }

    @Override
    public TaskResponseModel checkConflict(String key, RequestModel requestModel) {
        TaskResponseModel taskResponseModel = new TaskResponseModel().setKey(key).setResultCode(AcceptConstant.RESULT_SUCCESS_CODE).setResultMessage(AcceptConstant.RESULT_SUCCESS_MESSAGE);
        //渠道判断,蚂蚁直接结束
        if (StringUtils.equals(AgencyConstant.MY0201, requestModel.getPolicyInfo().getAgencyCode())) {
            return taskResponseModel;
        }
        if (!switchConfig.isSimilar()) {
            return taskResponseModel;
        }
        Set<String> idNos = new HashSet<>();
        Set<PersonModel> personModelSet = new HashSet<>();
        //投保人
        AppntModel appntModel = requestModel.getCustInfo().getAppnt();
        idNos.add(appntModel.getIdNo());
        personModelSet.add(new PersonModel().setName(appntModel.getAppntName()).setIdType(appntModel.getIdType()).setIdNo(appntModel.getIdNo()));
        //被保人
        List<InsurantModel> insurantModelList = requestModel.getCustInfo().getInsurants().getInsurant();
        for (InsurantModel insurantModel : insurantModelList) {
            idNos.add(insurantModel.getIdNo());
            personModelSet.add(new PersonModel().setName(insurantModel.getName()).setIdType(insurantModel.getIdType()).setIdNo(insurantModel.getIdNo()));
        }
        //受益人
        if (requestModel.getCustInfo().getBnfInfo() != null && requestModel.getCustInfo().getBnfInfo().getBeneficiaries() != null) {
            List<BeneficiaryModel> beneficiaryModelList = requestModel.getCustInfo().getBnfInfo().getBeneficiaries().getBeneficiary();
            if (CollectionUtils.isNotEmpty(beneficiaryModelList)) {
                for (BeneficiaryModel beneficiaryModel : beneficiaryModelList) {
                    idNos.add(beneficiaryModel.getBfcyIdCode());
                    personModelSet.add(new PersonModel().setName(beneficiaryModel.getBfcyName()).setIdType(beneficiaryModel.getBfcyIdType()).setIdNo(beneficiaryModel.getBfcyIdCode()));
                }
            }
        }
        String error;
        for (PersonModel personModel : personModelSet) {
            if (StringUtils.isNotBlank(error = AcceptUtil.checkIdCardValid(personModel))) {
                return taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE).setResultMessage(error);
            }
        }
        //查询白名单,任何一人存在白名单，校验结束
        List<String> whiteIdNos = userInfoRepository.queryWhiteList(idNos);
        if (CollectionUtils.isNotEmpty(whiteIdNos)) {
            return taskResponseModel;
        }
        //续期账户、账户名 非必传字段
        String accountNo = requestModel.getProductInfo().getBankAccNo();
        String accountName = requestModel.getProductInfo().getBankAccName();
        if (StringUtils.isNotBlank(accountNo) && StringUtils.isNotBlank(accountName) && accountInfoRepository.queryConflictingNameByBankAccountNo(accountName, accountNo) > 0) {
            return taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE).setResultMessage(UnderWriteConstant.UNDERWRITE_NUGG0060_MESSAGE);
        }
        //校验证件号重复 只校验身份证和户口本
        personModelSet = personModelSet.stream().filter(x -> IDCardCheck.checkIDCard(x.getIdNo())).collect(Collectors.toSet());
        if (CollectionUtils.isEmpty(personModelSet)) {
            return taskResponseModel;
        }
        List<String> conflictingIdNos = userInfoRepository.queryConflictingIdCardBatch(personModelSet);
        if (CollectionUtils.isNotEmpty(conflictingIdNos)) {
            List<String> upperConflictingIdNos = conflictingIdNos.stream().map(IDCardCheck::turnTo18).map(String::toUpperCase).collect(Collectors.toList());
            for (String conflictingIdNo : upperConflictingIdNos) {
                for (PersonModel personModel : personModelSet) {
                    if (StringUtils.equals(personModel.getIdNo18().toUpperCase(), conflictingIdNo)) {
                        return taskResponseModel.setResultCode(AcceptConstant.RESULT_FAIL_CODE).
                                setResultMessage(String.format(UnderWriteConstant.UNDERWRITE_NAME_CONFLICTING_MESSAGE, personModel.getName()));
                    }
                }
            }
        }
        return taskResponseModel;
    }
}
